package com.tj.collection.controller;

import com.alibaba.fastjson.JSON;
import com.fqgj.base.services.redis.RedisClient;
import com.tj.collection.aop.anno.VisitorAccessible;
import com.tj.collection.db.dao.ClMerchantDao;
import com.tj.collection.db.domain.Admin;
import com.tj.collection.db.entity.ClMerchantEntity;
import com.tj.collection.db.service.AdminService;
import com.tj.collection.utils.DbCacheConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: sm
 * Date: 2017/9/11
 * Time: 下午4:45
 */
@Controller
public class OkController {

//    private static final Loggerlogger = LoggerFactory.getLogger(OkController.class);

    private static final Logger logger = LoggerFactory.getLogger(OkController.class);

    @Value("${server.test}")
    private String testName;

    @Autowired
    private DbCacheConfig dbCacheConfig;

    @Autowired
    private ClMerchantDao clMerchantDao;

    @Autowired
    private AdminService adminService;

    @Autowired
    private RedisClient redisClient;

    @VisitorAccessible
    @RequestMapping("/ok")
    @ResponseBody
    public String ok() {
        return "post-lending,ok";
    }

    @VisitorAccessible
    @RequestMapping("/logok")
    @ResponseBody
    public String logok() {
        logger.info("testok,AAA111111222222333333," + testName);
        return "ok";
    }

    @VisitorAccessible
    @RequestMapping("/configok")
    @ResponseBody
    public String configok() {
        String value = dbCacheConfig.getProperty("audit.push.switch", "no");
        List<ClMerchantEntity> entityList = clMerchantDao.selectByParams(new HashMap<>());
        logger.info("查询结果," + JSON.toJSONString(entityList));

        Admin admin = adminService.getOneAdminByAccount("limenglin");
        logger.info("查询结果2," + JSON.toJSONString(admin));

        redisClient.set("a111111", "123123", 60);
        logger.info("66666666," + redisClient.get("a111111"));
        redisClient.del("a111111");

        return "ok," + value;
    }

}
